﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ex03.GarageLogic
{
    public abstract class FuelVehicle : Vehicle
    {
        private eFuelType m_FuelType;
        private float m_CurrentFuelLitresAmount;
        private float m_MaxFuelLitresAmount;

        public eFuelType FuelType
        {
            get { return m_FuelType; }
        }

        public float CurrentFuelLitresAmount
        {
            get { return m_CurrentFuelLitresAmount; }
        }

        public float MaxFuelLitresAmount
        {
            get { return m_MaxFuelLitresAmount; }
        }

        public override float LeftEnergyPercent
        {
            get { return CurrentFuelLitresAmount * 100 / MaxFuelLitresAmount; }
        }

        /// <summary>
        /// Refuels the vehicle with the given number of litres of the given fuel type.
        /// </summary>
        /// <param name="i_FuelLitresToAdd">The number of litres to add.</param>
        /// <param name="i_FuelTypeToAdd">The type of fuel to add.</param>
        public void Refuel(float i_FuelLitresToAdd, eFuelType i_FuelTypeToAdd)
        {
            if (i_FuelTypeToAdd != m_FuelType)
            {
                throw new ArgumentException("Incorrect fuel type.");
            }
            
            if (m_CurrentFuelLitresAmount + i_FuelLitresToAdd <= m_MaxFuelLitresAmount)
            {
                m_CurrentFuelLitresAmount += i_FuelLitresToAdd;
            }
            else
            {
                throw new ValueOutOfRangeException(m_CurrentFuelLitresAmount + i_FuelLitresToAdd, 0, m_MaxFuelLitresAmount);
            }
        }

        protected FuelVehicle(string i_ModelName, string i_LicensingNumber, List<Wheel> i_Wheels, eFuelType i_FuelType, float i_MaxFuelLitresAmount)
            : base(i_ModelName, i_LicensingNumber, i_Wheels)
        {
            m_FuelType = i_FuelType;
            m_CurrentFuelLitresAmount = 0;
            m_MaxFuelLitresAmount = i_MaxFuelLitresAmount;
        }

        public override Dictionary<string, string> GetAllProperties()
        {
            Dictionary<string, string> properties = base.GetAllProperties();

            properties.Add("Energy", "Fuel");
            properties.Add("Fuel Type", Enum.GetName(typeof(eFuelType), m_FuelType));
            properties.Add("Current Fuel Amount (Litres)", m_CurrentFuelLitresAmount.ToString());
            properties.Add("Maximal Fuel Amount (Litres)", m_MaxFuelLitresAmount.ToString());

            return properties;
        }
    }
}